package com.whiteape.book.widget;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.drawable.Drawable;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.whiteape.book.utils.DisplayUtil;

public class ComicLoadingDrawable extends Drawable {
    private Paint mBgPaint;
    private Paint mNumberPaint;
    private int mWidth;
    private int mHeight;
    private int mBgColor;
    private int mNumber;
    private float mTextSize;


    public ComicLoadingDrawable(int width, int height, int backgroundColor, int number) {
        mWidth = width;
        mHeight = height;
        mBgColor = backgroundColor;
        mNumber = number;
        mBgPaint = new Paint();
        mBgPaint.setColor(mBgColor);
        mNumberPaint = new Paint();
        mNumberPaint.setColor(Color.parseColor("#ffffff"));
        mTextSize = 50;
        mNumberPaint.setTextSize(mTextSize);
        mNumberPaint.setStrokeWidth(2);

    }

    @Override
    public void draw(@NonNull Canvas canvas) {
        canvas.drawRect(0, 0, mWidth, mHeight, mBgPaint);
        float textLength = mNumberPaint.measureText(mNumber+"");
        float start = (mWidth - textLength)/2;
        canvas.drawText(mNumber + "", start, mHeight/2, mNumberPaint);
//        canvas.drawText(mNumber + "", 200, mHeight/2, mNumberPaint);
//        canvas.drawText("你好啊世界", 10, 300, mNumberPaint);
//        canvas.drawCircle(300,300,50, mNumberPaint);

    }

    @Override
    public void setAlpha(int alpha) {

    }

    @Override
    public void setColorFilter(@Nullable ColorFilter colorFilter) {

    }

    @Override
    public int getOpacity() {
        return PixelFormat.UNKNOWN;
    }
}
